package com.tang.excel.oci.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.tang.excel.oci.domain.CommonDto;
import com.tang.excel.oci.domain.GullyWater;
import com.tang.excel.oci.mapper.GullyWaterMapper;
import com.tang.excel.oci.mapper.WarmGullyWaterMapper;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Tang
 * @classname GullyWaterListener
 * @description [ 雨水 ]
 * @date 2021/5/20 15:30
 */
public class GullyWaterListener extends AnalysisEventListener<GullyWater> {

    private GullyWaterMapper gullyWaterMapper;

    WarmGullyWaterMapper warmGullyWaterMapper;

    List<GullyWater> list = new ArrayList<>(10);
    List<CommonDto> commonDtos = new ArrayList<>(10);

    public GullyWaterListener(WarmGullyWaterMapper warmGullyWaterMapper) {
        this.warmGullyWaterMapper = warmGullyWaterMapper;
    }

    @Override
    public void invoke(GullyWater gullyWater, AnalysisContext analysisContext) {
        gullyWater.setCodValue(Double.valueOf(gullyWater.getCod().replace("(mg/L)", "")));
        gullyWater.setEmissionsValue(Integer.valueOf(gullyWater.getEmissions().replace("(吨)", "")));
        gullyWater.setWastewaterFlowValue(Double.valueOf(gullyWater.getWastewaterFlow().replace("(L/s)", "")));
        commonDtos.add(new CommonDto(gullyWater.getSaveDate(),gullyWater.getCodValue(),"COD",2));
        commonDtos.add(new CommonDto(gullyWater.getSaveDate(),gullyWater.getWastewaterFlowValue(),"wastewaterFlow",2));
        commonDtos.add(new CommonDto(gullyWater.getSaveDate(),gullyWater.getEmissionsValue() + 0.0,"emissions",2));
        commonDtos.add(new CommonDto(gullyWater.getSaveDate(),gullyWater.getPh(),"ph",2));
        list.add(gullyWater);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        warmGullyWaterMapper.batchInsert2(commonDtos);
    }
}